﻿@{
    @using Microsoft.AspNetCore.Http;
    Layout = null;
    ViewData["Title"] = "Index";
}
<script src="~/js/vue.js"></script>
<script src="~/js/axios.js"></script>
<script src="~/element-ui/lib/index.js"></script>
<link rel="stylesheet" href="~/element-ui/lib/theme-chalk/index.css" />
<h1>职位发布登记JobRegist</h1>
<div id="app">
    <el-form ref="form" :model="formData" label-width="80px">
        @*第一行*@
        <el-row>
            <el-col :span="6">
                <el-form-item label="I级机构">
                    <el-select v-model="first_kind" placeholder="请选择" value-key="first_kind_id">
                        <el-option v-for="item in fks"
                                   :key="item.first_kind_id"
                                   :label="item.first_kind_name"
                                   :value="item">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="II级机构">
                    <el-select v-model="second_kind" placeholder="请选择" value-key="second_kind_id">
                        <el-option v-for="item in sks"
                                   :key="item.second_kind_id"
                                   :label="item.second_kind_name"
                                   :value="item">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="III级机构">
                    <el-select v-model="third_kind" placeholder="请选择" value-key="third_kind_id">
                        <el-option v-for="item in tks"
                                   :key="item.third_kind_id"
                                   :label="item.third_kind_name"
                                   :value="item">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            @*<el-col :span="6">
                <el-form-item label="III级机构">
                    <el-cascader v-model="cmkValue"
                                 :options="cmks"
                                 :props="optionProps"
                                 v-on:change="handleChange" ref="cmkk"></el-cascader>
                </el-form-item>
            </el-col>*@

            <el-col :span="6">
                <el-form-item label="招聘类型">
                    <el-select v-model="engage_type" placeholder="请选择">
                        <el-option v-for="item in ets"
                                   :key="item.engage_type"
                                   :label="item.label"
                                   :value="item.engage_type">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-col>
        </el-row>
        @*第二行*@
        <el-row>
            <el-col :span="6">
                @*注意：这里联级子集主键名需为id*@
                <el-form-item label="职位分类">
                    <el-cascader v-model="cmkValue"
                                 :options="cmks"
                                 :props="optionProps"
                                 v-on:change="handleChange" ref="cmkk"></el-cascader>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="招聘人数">
                    <el-input v-model="engagenum"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="截至日期">
                    <el-date-picker v-model="clsDate"
                                    type="datetime"
                                    placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
            </el-col>
        </el-row>
        @*第三行*@
        <el-row>
            <el-col :span="6">
                <el-form-item label="登记人">
                    @Context.Session.GetString("uname")
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="登记时间">
                    <el-date-picker v-model="opeDate"
                                    type="datetime"
                                    placeholder="选择日期时间" :disabled="true">
                    </el-date-picker>
                </el-form-item>

            </el-col>
        </el-row>
        @*第四行*@
        <el-row>
            <el-col :span="18">
                <el-form-item label="职位描述">
                    <el-input type="textarea"
                              :rows="5"
                              placeholder="请输入职业描述"
                              v-model="major_describe">
                    </el-input>
                </el-form-item>
            </el-col>
        </el-row>
        @*第五行*@
        <el-row>
            <el-col :span="18">
                <el-form-item label="招聘要求">
                    <el-input type="textarea"
                              :rows="5"
                              placeholder="请输入招聘要求"
                              v-model="engage_required">
                    </el-input>
                </el-form-item>
            </el-col>
        </el-row>
        <el-form-item>
            <el-button type="primary" v-on:click="onSubmit">立即创建</el-button>
        </el-form-item>
    </el-form>
</div>

<script type="text/javascript">
    var vue = new Vue({
        el: "#app",
        data: {
            //职位类型联级选择器数据源
            cmks: [],
            //选中项绑定值
            cmkValue: [],
            //次级菜单的展开方式和数据源绑定
            optionProps: {
                expandTrigger: 'hover',
                value: 'id',
                label: 'name',
                children: 'children'
            },
            //职位类型联级选择器数据源
            cmks: [],
            //选中项绑定值
            cmkValue: [],
            //次级菜单的展开方式和数据源绑定
            optionProps: {
                expandTrigger: 'hover',
                value: 'id',
                label: 'name',
                children: 'children'
            },

            //I级机构
            fks: [],
            first_kind: {
                first_kind_id: '',
                first_kind_name: '',
            },
            //II级机构
            sks: [],
            second_kind: {
                second_kind_id: '',
                second_kind_name: '',
            },
            //III级机构
            tks: [],
            third_kind: {
                third_kind_id: '',
                third_kind_name: '',
            },
            //招聘类型下拉列表框
            ets: [{
                engage_type: '校园招聘',
                label: '校园招聘'
            }, {
                engage_type: '社会招聘',
                label: '社会招聘'
            }],
            engage_type: '',
            //招聘人数
            engagenum: '',
            //终止招聘时间
            clsDate: '',
            //起始招聘时间
            opeDate: '',
            //职位描述
            major_describe: '',
            //招聘要求
            engage_required: '',
            //职位发布登记表实体类
            //engage_major_release: {},
        },
        methods: {
            //一二三级机构下拉列表框选择项
            fstkinds() {
                axios.get("/ConfigFile/fstKindsFill").then(res => {
                    this.fks = res.data[0].tabs;
                    this.sks = res.data[1].tabs;
                    this.tks = res.data[2].tabs;
                });
                axios.get("/EngageResume/CMKCascader").then(res => {
                    console.info("CMKCascader/res.data:", res.data);
                    this.cmks = res.data;
                });
                //获取session中的当前登录的用户名
                console.info("sessionUname:啊啊啊");
                var uname = Session["uname"];
                console.info("sessionUname:", uname);
            },
            //获取当前时间
            getNowTime() {
                var now = new Date();
                var year = now.getFullYear(); //获取年
                var month = now.getMonth();//获取月
                var date = now.getDate();//获取日
                var hours = now.getHours();//获取小时
                var minutes = now.getMinutes();//获取分钟
                var seconds = now.getSeconds();//获取秒
                month = month + 1;
                month = month.toString().padStart(2, "0");
                date = date.toString().padStart(2, "0");
                var defaultDate = `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
                this.opeDate = new Date();
            },
            //定义时间戳
            created() {
                setInterval(() => {
                    this.getNowTime();
                }, 500);
            },
            //职位发布登记
            onSubmit() {
                //console.info("this.first_kind.first_kind_id:", this.first_kind.first_kind_id, this.first_kind.first_kind_name,
                //    this.second_kind.second_kind_id, this.second_kind.second_kind_name,
                //    this.third_kind.third_kind_id, this.third_kind.third_kind_name,
                //    this.config_major_kind.major_kind_id, this.config_major_kind.major_kind_name,
                //    this.config_public_char.pbc_id, this.config_public_char.attribute_name,
                //    this.engagenum, this.clsDate, this.engage_type, this.opeDate, this.major_describe, this.engage_required,
                //);
                axios.post("/JobRegist/EngageMajorReleaseAdd", {
                    first_kind_id: this.first_kind.first_kind_id,
                    first_kind_name: this.first_kind.first_kind_name,
                    second_kind_id: this.second_kind.second_kind_id,
                    second_kind_name: this.second_kind.second_kind_name,
                    third_kind_id: this.third_kind.third_kind_id,
                    third_kind_name: this.third_kind.third_kind_name,
                    major_kind_id: this.cmkValue[0].toString(),
                    major_kind_name: this.$refs['cmkk'].getCheckedNodes()[0].pathLabels[0],
                    major_id: this.cmkValue[1].toString(),
                    major_name: this.$refs['cmkk'].getCheckedNodes()[0].pathLabels[1],
                    human_amount: this.engagenum,
                    deadline: this.clsDate,
                    engage_type: this.engage_type,
                    regist_time: this.opeDate,
                    major_describe: this.major_describe,
                    engage_required: this.engage_required,
                }).then(res => {
                    if (res.data > 0) {
                        this.first_kind = {};
                        this.second_kind = {};
                        this.third_kind = {};
                        this.cmkValue = [];
                        this.engagenum = '';
                        this.clsDate = '';
                        this.engage_type = '';
                        this.major_describe = '';
                        this.engage_required = '';
                        this.opensuc();
                    }
                });
            },
            //操作成功弹窗
            opensuc() {
                this.$message({
                    message: '恭喜你，发布招聘信息成功！',
                    type: 'success'
                });
            },
        },
        mounted: function() {
            this.created();
            this.fstkinds();
        }
    });

</script>